package com.fruit.api.controller.fruit;

import com.fruit.bean.dto.fruit.FruitProfitInfoDto;
import com.fruit.bean.dto.fruit.FruitStockOrderInfoDto;
import com.fruit.bean.entity.fruit.FruitProfitInfo;
import com.fruit.bean.entity.system.FileInfo;
import com.fruit.bean.vo.front.Rets;
import com.fruit.service.fruit.FruitProfitService;
import com.fruit.service.system.FileService;
import com.fruit.utils.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/fruit/profit")
public class FruitProfitController {

    @Autowired
    private FruitProfitService profitService;

    @Autowired
    private FileService fileService;

    @RequestMapping("/list")
    public Object getProfitList(){
        List<FruitProfitInfoDto> profitInfoDtoList = profitService.listProfit();
        return Rets.success(profitInfoDtoList);
    }

    @RequestMapping("/list/total")
    public Object getProfitListTotal(){
        List<FruitProfitInfoDto> profitInfoDtoList = profitService.listProfitTotal();
        for(FruitProfitInfoDto profitInfoDto : profitInfoDtoList){

        }
        return Rets.success(profitInfoDtoList);
    }

    @RequestMapping("/export")
    public Object exportProfitList(){
        List<FruitProfitInfoDto> profitInfoDtoList = profitService.listProfit();
        FileInfo fileInfo = fileService.createExcel("templates/profit.xlsx",
                "收益明细.xlsx",
                Maps.newHashMap("list", profitInfoDtoList));
        return Rets.success(fileInfo);
    }

    @RequestMapping("/export/total")
    public Object exportProfitTotalList(){
        List<FruitProfitInfoDto> profitInfoDtoList = profitService.listProfitTotal();
        FileInfo fileInfo = fileService.createExcel("templates/profitTotal.xlsx",
                "收益总览.xlsx",
                Maps.newHashMap("list", profitInfoDtoList));
        return Rets.success(fileInfo);
    }
}
